// 新顾客的到来newCustomer
function newCustomer(id,waitingTime){
    const change= 20 //用于展示进度条的函数
    let firstColor = 0 //一个用于满进度
    let secondColor = 120 //一个用于进度条的削弱
    const id_temp = id //生成一个可以操作的id的临时变量
    let parentElment = $("wait-box")
    //刚开始时的padding值，用于添加到来的顾客
    startPadding -= changePadding
    //真实用于变量里面的值
    let paddingLeft = "padding-left:" + startPadding+"vw"
    //创建一个新的div
    let div_waiting = document.createElement("div")
    div_waiting.innerHTML =  "<div class=\"customer-icon\">\n"+
    "               <img src=\"./img/customer"+id_temp +".png\">\n" +
    "</div>\n"+
    "<div class=\"waiting-text\" id=\"waiting-text"+id_temp +"\">\n"+
    "                   等位中\n"+
    "</div>\n";
    //设置其的值为watiing
    div_waiting.className= "waiting";
    //设置其的id值，将其进行后期更好的获取其的dom操作
    div_waiting.id = "waiting"+ id_temp;
    //在wait-box里面添加一个孩子
    parentElment.appendChild(div_waiting);
    //设置其的padding-left的值来进行后期的值排列
    parentElment.setAttribute("style",paddingLeft)
    //获取刚刚创建那个子级的div
    let waitingTimeBox = $("waiting-text" +id_temp);
    //获取刚刚创建里面那个div里面元素的值
    let waitingBox = $("waiting"+id_temp)
    //判断是否可以入座
    const newWaitingListenr=()=>{
        if(eatingNumber < 4){
            //假如正在吃饭的人数小于4的话，则将排队的人从possible转变为ready状态
            let readyCustomer = waitingList.shift()//抽取列表的第一个
            arrageSeat(readyCustomer)//给你安排座位
            //同时需要删掉正在排队中的用户
            let delWait = $("waiting"+readyCustomer)
            deleteCustomer(parentElment,delWait,"ready",readyCustomer)
        }else{
            //没有座位的话，提示当前是没有座位
            ElMessage("warning","餐厅目前没有空位，耐心等待",1500)
        }
    }
    //监听点击用户的头像来进行入座处理
    waitingBox.addEventListener("click",newWaitingListenr);
    let timer = setInterval(()=>{
        firstColor +=change;
        secondColor -= change;
        let background = "background: linear-gradient(-90deg, #2693ff " + firstColor + "%, #006dd9 0" + ", #006dd9 " + secondColor + "%);";
        //设置等位中的进度条的展示
        waitingTimeBox.setAttribute("style",background);
        if(firstColor ===100){//等待了5秒，然后删除一个
            clearInterval(timer);
            if(waitingList.indexOf(id_temp) !== -1){
                //删除该元素
                deleteCustomer(parentElment,waitingBox,"impossible",id_temp);
                waitingList.shift();//从数据中删除该选项
            }

        }
    },waitingTime)

}
//删除正在等待列表中的顾客，修改顾客的状态deleteCustomer
function deleteCustomer(parentElment,waitingBox,status,id){
    if(typeof waitingBox ==="object"){
        if(parentElment.children.length >0){
            parentElment.removeChild(waitingBox);
        }
        startPadding +=changePadding;
        paddingLeft ="padding-left:"+startPadding +"vw";
        parentElment.setAttribute("style",paddingLeft);
        customer[id].status = status;
    }
}
//安排顾客入座
function arrageSeat(id){
    for(let i in table){
        if(table[i].canUse === true){
            table[i].id = id;
            eatingNumber++;
            //打开点菜的菜单
            handleOpenMenu(id,i)//传入该用户的id和座位好，用于后期的绑定的动作
            break;
        }
    }
    console.log("安排座位");

}
//更新顾客的转态updateCustomerStatus
function changeCustomerStatus(id,menu){
    customer[id].status = "impossible";
    menu.style.display ="none"
}
//吃饭
function eatFood(seatNumber,foodDivIndex,background,foodPrice){
    let firstColor = 0;
    let secondColor = 100;
    table[seatNumber].money = parseInt(table[seatNumber].money) + parseInt(foodPrice);
    let timer = setInterval(()=>{
        firstColor += eatingChange;
        secondColor -= eatingChange;
        background = "background: linear-gradient(-90deg, #" + color[seatNumber].color2 + " " + firstColor + "%, #" + color[seatNumber].color1 + " " + "0,#" + color[seatNumber].color1 + " " + secondColor + "%)";
        foodDivIndex.setAttribute("style",background);
        if(secondColor <=0){
            //吃饭时间到之后进行收钱
            table[seatNumber].dealCount +=1;//计算用户是否把自己的菜品吃完
            getMoney(seatNumber);
            clearInterval(timer);
            
        }
    },eatingTime / 5)

}